package com.xbj.controller;

import cn.hutool.core.bean.BeanUtil;
import com.xbj.db.pojo.Pay;
import com.xbj.db.pojo.PayDTO;
import com.xbj.service.PayService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author: 观雾
 * @create: 2024-07-16
 * @description:
 **/
@RestController
public class PayController {

    @Resource
    private PayService payService;

    @PostMapping(value = "/pay/add")
    public String addPay(@RequestBody Pay pay){
        int addCount = payService.add(pay);

        return "成功插入"+addCount+"记录";
    }

    @DeleteMapping(value = "/pay/del/{id}")
    public Integer detelePay(@PathVariable("id") Integer id){
        int deleteCount = payService.delete(id);
        return deleteCount;
    }

    @PutMapping(value = "/pay/update")
    public String updatePay(@RequestBody PayDTO payDTO){
        Pay pay = new Pay();
        BeanUtil.copyProperties(payDTO,pay);
        int updateCount = payService.update(pay);
        return "成功更新"+updateCount+"记录";
    }

    @GetMapping(value = "/pay/getById/{id}")
    public Pay getById(@PathVariable("id") Integer id){
        Pay pay = payService.getById(id);
        return pay;
    }
    @GetMapping(value = "/pay/getById")
    public Pay getById(){
        Pay pay = payService.getById(2);
        return pay;
    }
    @GetMapping(value = "/pay/getAll")
    public List<Pay> getAll(){
        List<Pay> payList = payService.getAll();
        return payList;
    }
}
